/**
 * 功能描述 联盟团信息导航条
 */

define(function (require, exports, module) {
	var Form = require("form");
	var enmu = require("enums");
	var Dialog = require("dialog");
	
	var store =require("store");
	var activeUser = store.get("user");	
	
    var instance = {
        initComponent: function (params, widget) {
            var form = new Form({
            	parentNode : ".J-form",
            	model : {
                    id: "form",
                    defaultButton : false,
                    layout: "3_1",
                    items: [{
                    	name : "pkNonMemberGroup",
                    	type : "hidden"
                    },{
                    	name : "version",
                    	type : "hidden",
                		defaultValue : "0"
                    },{
                    	name : "status",
                    	type : "hidden",
                    	defaultValue : "Initial"
                    },{
                    	name : "servicePoint",
                    	label : "目的地",
                    	type : "select",
                    	keyField : "pkServicePoint",
                    	valueField : "name",
                    	validate:["required"],
                    },{
                    	name : "checkInDate",
                    	label : "入住日期",
                    	type : "date",
                    	events: {
//							"change": function(e){
//								var form = widget.get("form");
//				        		var startDate = form.getValue("planItem.startDate");
//				        		var endDate = form.getValue("planItem.endDate");
//				        		if(startDate !="" && endDate != "" && startDate > endDate){
//				        			Dialog.alert({
//				        				tip : "提示",
//				        				content : "开始日期不能晚于结束日期！"
//				        			})
//				        			form.setValue("startDate", "");
//				        		}
//							}
						},
                    	validate:["required"],
                    },{
                    	name : "checkOutDate",
                    	label : "退房日期",
                    	type : "date",
                    	validate:["required"],
                    },{
	                   	name : "contactName",
	                	label : "联系人",
						validate:["required"],
                    },{
	                   	name : "contactPhone",
	                	label : "联系电话",
						validate:["required"],
                    },{
                   	 	name : "chargeDeposit",
                   	 	label : "是否收取订金",
                   	 	type : "select",
                   	 	validate:["required"],
                   	 	options : [{
                   	 		key : "true",
                   	 		value : "是"
                   	 	},{
                   	 		key : "false",
                   	 		value : "否"
                   	 	}],
                   	 	events : {
                   	 		"change" : function(e){
	                   	 		var form = widget.get("form");
				        		var chargeDeposit = form.getValue("chargeDeposit");
				        		if(chargeDeposit == "false"){
				        			form.setDisabled("deposit", true);
				        			form.setValue("deposit", "");
				        		}else{
				        			form.setDisabled("deposit", false);
				        		}
                   	 		}
                   	 	},
                   	 	validate:["required"],
                    },{
                   	 	 name : "deposit",
                         label : "订金金额",
                         events : {
                        	 "change" : function(e){
                        		 var deposit = widget.get("form").getValue("deposit");
                        		 if(!isNaN(deposit) && parseInt(deposit) > 0){
                        			 widget.get("form").setValue("deposit", parseFloat(deposit).toFixed(2));
                        		 } else{
                        			 Dialog.alert({
                        				 tip : "提示",
                        				 content : "订金金额必须输入数字且不能为负！"
                        			 });
                        			 widget.get("form").setValue("deposit", "");
                        			 return false;
                        		 }
                        	 }
                         }
                    },{
                   	 	 name : "perNumber",
	                     label : "入住人数",
	                     validate:["required"],
	                     events:{
	                    	 "change":function(e){
                    		 	var reg = /^[0-9]*[1-9][0-9]*$/;
								if(!reg.test(form.getValue("perNumber"))){
									Dialog.alert({
										tip: "提示！",
										content: "入住人数只能输入正整数！"
									});
									return false;
								}
	                    	 }
	                     }
                    },{
                    	name : "tourType",
                    	label : "入住类型",
                    	type : "select",
                    	options:enmu["com.eling.elcms.travel.model.NonMemberGroup.TourType"],
                    	validate:["required"],
                    	events: {
							"change": function(e){
								var form = widget.get("form");
				        		var tourType = form.getValue("tourType");
				        		if(tourType == "IndivMember"){
				        			$("th[data-name='signUpRegister.travelContract.memberCertificates']").show();
				        			$(".J-grid-columns-signUpRegister-travelContract-memberCertificates").removeClass("hidden");
				        		}else{
				        			$("th[data-name='signUpRegister.travelContract.memberCertificates']").hide();
				        			$(".J-grid-columns-signUpRegister-travelContract-memberCertificates").addClass("hidden");
				        		}
							}
						},
                    },{
                    	name : "signUpType",
                    	type : "hidden",
                    	defaultValue : "NonMember",
                    	validate:["required"],
                    },{
                    	name:"isWaterElectric",
						label:"是否含水电费",
						type:"radio",
						validate:["required"],
	        			list:[{
	        				key:"true",
	        				value:"是"
	        				},{
	        				key:"false",
	        				value:"否"
	        			}]
                    },{
	                   	 name : "operatorName",
	                   	 label : "登记人",
	                   	 defaultValue : activeUser.name,
	                   	 readonly : true
                    },{
	                   	 name : "operator",
	                   	 type : "hidden",
	                   	 defaultValue : activeUser.pkUser
                    },{
	                   	 name : "isAbolished",
	                   	 type : "hidden",
	                   	 defaultValue : false
                    },{
                    	 name : "operateDate",
                         type : "date",
                         label : "登记日期",
                         mode : "YYYY-MM-DD",
                         readonly : true,
                         defaultValue : moment(new Date()),
                    },{
                   	 	 name : "description",
	                     label : "备注",
	                     "break" : true
                    }]
                }
            })
        	widget.set("form", form);
        }
    };
    module.exports = instance;
});
